import React from "react";
import store from '../../store'

export default class Count extends React.Component {
  state = {num: 0}

  componentDidMount = ()=> {
    store.subscribe(() => {
      this.setState({})
    })
  }

  increment = () => {
    const {value} = this.inputEl
    console.log("increment value")
    console.log(value)
    // 参数对象，就是 action 的概念。
    store.dispatch({type: "increment", data: 1*value});
  }
  render() {
    const {num} = this.state
    // store.getState() 获取的是来自 Reducers 的返回值。
    return (
      <div>
        <p>{num} -- {store.getState()}</p>

        <input type="number" ref={(el)=>{this.inputEl = el}} value="1" step="10" min="0" max="100" />
        <button onClick={this.increment}>点击+</button>
      </div>
    )
  }
}
